//import copy from 'copy-to-clipboard';
//import ReactDOM from 'react-dom';
import {message} from "antd";

export class sys {
  //只显示一个正确消息
  static msgsucconly(msg) {
    message.destroy();
    message.success(msg);
  }

  //只显示一个错误消息
  static msgerronly(msg) {
    message.destroy();
    message.error(msg);
  }

  //显示一个正确消息
  static msgsucc(msg) {
    message.success(msg);
  }

  //显示一个错误消息
  static msgerr(msg) {
    message.error(msg);
  }


  //深度克隆对象
  static getObjClass(obj) {
    let result = Object.prototype.toString.call(obj).slice(8, -1);
    if (result === 'Null') {
      return 'Null';
    } else if (result === 'Undefined') {
      return 'Undefined';
    } else {
      return result;
    }
  }

  //深度克隆对象
  static deepClone(obj) {
    let result, objClass = sys.getObjClass(obj);
    if (objClass === 'Object') {
      result = {};
    } else if (objClass === 'Array') {
      result = [];
    } else {
      return obj; // 如果是其他数据类型不复制，直接将数据返回
    }
    // 遍历目标对象
    for (let key in obj) {
      let value = obj[key];
      if (sys.getObjClass(value) === "Object" || 'Array') {
        result[key] = sys.deepClone(value);
      } else {
        result[key] = obj[key];
      }
    }
    return result;
  }

  //重复运行次数
  static runTime(fun, timeNumber) {
    Array.from({length: timeNumber}).map(fun);//设置执行10层递归
  }

  //判断是否是移动端设备还是电脑设备
  static is_phone() {
    var userAgentInfo = navigator.userAgent;
    var Agents = [
      "Android",
      "iPhone",
      "SymbianOS",
      "Windows Phone",
      "iPad",
      "iPod",
    ];
    var flag = false;
    for (var v = 0; v < Agents.length; v++) {
      if (userAgentInfo.indexOf(Agents[v]) > 0) {
        flag = true;
        break;
      }
    }
    return flag;
  }

  //判断是否是ios系统
  static is_ios() {
    return !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  }

  //判断是否是android系统
  static is_android() {
    let ua = navigator.userAgent.toLowerCase();
    return ua.indexOf("android") > -1 || ua.indexOf("adr") > -1;
  }

  //是否是微信中打开的网页
  static is_webkit() {
    var ua = navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i) === "micromessenger") {
      return true;
    }
    return false;
  }

  //获取定位信息
  static geolocation() {
    if (navigator.geolocation) {
      //判断是否有这个对象
      navigator.geolocation.getCurrentPosition((e) => {
        sys.alert(e);
      });
    } else {
      sys.alert("当前系统不支持GPS API");
    }
  }

  //判断网络是否畅通
  static is_onLine() {
    return navigator.onLine;
  }

  static getsss() {
    return window.plus.device.imei;
  }

  //拨打电话
  static callTel(aTel) {
    window.open("tel:" + aTel);
  }

  //发送短信
  static callSms(aTel, aText) {
    window.open("sms://" + aTel + "?body=" + aText);
  }

  //android震动
  static zhendongAndroid(pattern) {
    navigator.vibrate(pattern || 500);
  }

  static fangxiang() {
    if (window.DeviceOrientationEvent) {
      window.addEventListener("deviceorientation", (e) => {
        console.log(e.alpha);
        console.log(e.beta);
        console.log(e.gamma);
      });
    } else {
      // 不支持
    }
  }

  //设置页面标题
  static setTitle(aTitle) {
    document.title = aTitle;
  }

  //播放mp3
  static playMp3(aMp3FilePath) {
    let id = sys.rand_string("", 10, 10);
    sys.insertHtmlBody(
      `<audio src='${aMp3FilePath}' style='display:none' id='audio_${id}'></audio>`
    );

    document.getElementById("audio_" + id).play();
  }

  //打印日志
  static log(aStr) {
    console.log(aStr);
  }

  //获取域名
  static getDomain() {
    return document.domain;
  }

  //设置文本到剪贴板
  /*     static setClipboardData(aStr) {
        return copy(aStr);
    } */

  //获取当前完整url
  static getUrlAll() {
    return window.location.href;
  }

  //获取部分url
  static getUrlParameter() {
    return window.location.pathname;
  }

  /**
   * 替换url参数并且替换
   * @param paramName
   * @param replaceWith
   */
  static replaceParamVal(paramName, replaceWith) {
    let oUrl = this.location.href.toString();
    let re = eval("/(" + paramName + "=)([^&]*)/gi");
    let nUrl = oUrl.replace(re, paramName + "=" + replaceWith);
    this.location = nUrl;
    window.location.href = nUrl;
  }

  //跳转到指定页面 ,或者下载文件
  static jumpUrl(aUrl) {
    window.location.href = aUrl || "https://baidu.com";
  }

  //跳转到指定页面新页面
  static jumpUrlNewTab(aUrl) {
    window.open(aUrl || "https://baidu.com");
  }

  //刷新本页
  static jumpReload() {
    window.location.reload();
  }

  //后退本页
  static jumpGoBack() {
    window.history.go(-1);
  }

  //前进本页
  static jumpGoBefore() {
    window.history.go(1);
  }

  //跳转到微信
  static jumpToWeixin() {
    window.location.href = "weixin://";
  }

  //跳转到淘宝
  static jumpToTaoBao() {
    window.location.href = "taobao://";
  }

  //跳转到指定app
  static jumpToApp(aApp) {
    window.location.href = aApp + "://";
  }

  //获取设备的字符串
  static get_useragent() {
    return navigator.userAgent;
  }

  //获取当前宽度
  static clientWidth() {
    return document.body.clientWidth;
  }

  //获取当前高度
  static clientHeight() {
    return document.body.clientHeight;
  }

  //获取一个随机的GUID
  static getGUID() {
    return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (
      c
    ) {
      var r = (Math.random() * 16) | 0,
        v = c === "x" ? r : (r & 0x3) | 0x8;
      return v.toString(16);
    });
  }

  static hexToRgb(hex, a = 1) {
    let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
    return result
      ? "rgba(" +
      parseInt(result[1], 16) +
      "," +
      parseInt(result[2], 16) +
      "," +
      parseInt(result[3], 16) +
      "," +
      a +
      ")"
      : null;
  }

  static isArray(aObject) {
    if (aObject instanceof Array) {
      return true;
    } else {
      return false;
    }
  }

  static isNumber(aObject) {
    const regPos = /^\d+(\.\d+)?$/; //非负浮点数
    const regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数

    if (regPos.test(aObject) || regNeg.test(aObject)) {
      return true;
    } else {
      return false;
    }
  }

  /* //md5加密
    static md5(str) {
        return CryptoJS.MD5(str).toString();
    }

    //aes加密
    static aes_encode(str, key = 'app_key', iv = 'app_iv') {
        var i_key = this.md5('&&&' + this.md5(key) + '@#@');
        var i_iv = this.md5('***' + this.md5(iv) + '@#@');
        return CryptoJS.AES.encrypt(str, i_key, {iv: i_iv, padding: CryptoJS.pad.ZeroPadding}).toString();
    }

    //aes解密
    static aes_decode(en_str, key = 'app_key', iv = 'app_iv') {
        var i_key = this.md5('&&&' + this.md5(key) + '@#@');
        var i_iv = this.md5('***' + this.md5(iv) + '@#@');
        var decrypt = CryptoJS.AES.decrypt(en_str, i_key, {iv: i_iv, padding: CryptoJS.pad.ZeroPadding});
        return decrypt.toString(CryptoJS.enc.Utf8);
    } */

  /**
   * 用于数组列表显示时候改变数据的
   * @param aAryData
   * @param fenZuChangDu
   * @returns {Array}
   */
  static set_new_ary(aAryData, fenZuChangDu) {
    if (fenZuChangDu < 1) return [];
    let aAry = [];
    let index = 0;
    let newIndex = 0;
    while (index < aAryData.length) {
      aAry[newIndex] = [];
      for (let i = 0; i < fenZuChangDu; i++) {
        let tempInt = newIndex * fenZuChangDu + i;
        if (tempInt < aAryData.length) {
          aAry[newIndex][i] = aAryData[tempInt];
        } else {
          //aAry[newIndex][i]=null;
          break;
        }
      }
      newIndex = newIndex + 1;
      index = index + fenZuChangDu;
    }
    return aAry;
  }

  //获取浏览器最外层窗口
  static getWinTop() {
    return window.top;
  }

  /**************************************************************************************************/
  /**
   * 添加 cookie
   * @param name 名称
   * @param value 值
   * @param expiresHours 过期时间
   */
  static addCookie(name, value, expiresHours) {
    let cookieString = `${name}=${escape(value)}`;
    // 判断是否设置过期时间,0代表关闭浏览器时失效
    if (expiresHours > 0) {
      const date = new Date();
      date.setTime(date.getTime() + expiresHours * 1000 * 60 * 60);
      cookieString = `${cookieString};expires=${date.toUTCString()}`;
    }
    document.cookie = cookieString;
  }

  /**
   * 修改 cookie
   * @param name 名称
   * @param value 值
   * @param expiresHours 过期时间
   */
  static editCookie(name, value, expiresHours) {
    let cookieString = `${name}=${escape(value)}`;
    if (expiresHours > 0) {
      const date = new Date();
      date.setTime(date.getTime() + expiresHours * 1000 * 60 * 60); // 单位是毫秒
      // @ts-ignore
      cookieString = `${cookieString};expires=${date.toGMTString()}`;
    }
    document.cookie = cookieString;
  }

  /**
   * 根据名字获取cookie的值
   * @param name
   */
  static getCookieValue(name) {
    const strCookie = document.cookie;
    const arrCookie = strCookie.split("; ");
    for (const cookie of arrCookie) {
      const arr = cookie.split("=");
      if (arr[0] === name) {
        //console.log('unescape(arr[1])', unescape(arr[1]));
        return unescape(arr[1]);
      }
    }
  }

  /**
   * 删除cookie
   * @param name
   */
  static delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = sys.getCookieValue(name);
    if (cval != null)
      document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
  }

  /**
   * 删除所有cookie
   */
  static delCookieAll() {
    let date = new Date();
    date.setTime(date.getTime() - 10000);
    let keys = document.cookie.match(/[^ =;]+(?=\=)/g);
    if (keys) {
      for (let i = keys.length; i--;)
        document.cookie =
          keys[i] + "=0; expire=" + date.toGMTString() + "; path=/";
    }
  }

  /**时间相关*****************************************************************************************/
  static get get_year() {
    const AppDate = new Date();
    return AppDate.getYear(); //获取当前年份(2位)
  }

  static get get_full_year() {
    const AppDate = new Date();
    return AppDate.getFullYear(); //获取完整的年份(4位,1970-????)
  }

  static get get_month() {
    const AppDate = new Date();
    return AppDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
  }

  static get get_date() {
    const AppDate = new Date();
    return AppDate.getDate(); //获取当前日(1-31)
  }

  static get get_day() {
    const AppDate = new Date();
    return AppDate.getDay() + 1; //获取当前星期X(0-6,0代表星期天)
  }

  static get get_time() {
    const AppDate = new Date();
    return AppDate.getTime(); //获取当前时间(从1970.1.1开始的毫秒数)
  }

  static get get_hours() {
    const AppDate = new Date();
    return AppDate.getHours(); //获取当前小时数(0-23)
  }

  static get get_minutes() {
    const AppDate = new Date();
    return AppDate.getMinutes(); //获取当前分钟数(0-59)
  }

  static get get_seconds() {
    const AppDate = new Date();
    return AppDate.getSeconds(); //获取当前秒数(0-59)
  }

  static get get_milli_seconds() {
    const AppDate = new Date();
    return AppDate.getMilliseconds(); //获取当前毫秒数(0-999)
  }

  static get date_string() {
    const AppDate = new Date();
    const year = AppDate.getFullYear();
    const month = AppDate.getMonth() + 1;
    const date = AppDate.getDate();

    return (
      `${year}-` +
      `${sys.PrefixInteger(month, 2)}-` +
      `${sys.PrefixInteger(date, 2)}`
    );
  }

  static get date_time_string() {
    const AppDate = new Date();
    const year = AppDate.getFullYear();
    const month = AppDate.getMonth() + 1;
    const date = AppDate.getDate();
    const hh = AppDate.getHours();
    const mm = AppDate.getMinutes();
    const ss = AppDate.getSeconds();

    return (
      `${year}-` +
      `${sys.PrefixInteger(month, 2)}-` +
      `${sys.PrefixInteger(date, 2)} ` +
      `${sys.PrefixInteger(hh, 2)}:` +
      `${sys.PrefixInteger(mm, 2)}:` +
      `${sys.PrefixInteger(ss, 2)}`
    );
  }

  static PrefixInteger(num, length) {
    return ("0000000000000000" + num).substr(-length);
  }

  //字符串转时间格式字符串
  static dateFormat(fmt = "YYYY-mm-dd HH:MM:SS", datestr) {
    try {
      const oldtime = new Date(datestr);
      let ret;
      const opt = {
        "Y+": oldtime.getFullYear().toString(), // 年
        "m+": (oldtime.getMonth() + 1).toString(), // 月
        "d+": oldtime.getDate().toString(), // 日
        "H+": oldtime.getHours().toString(), // 时
        "M+": oldtime.getMinutes().toString(), // 分
        "S+": oldtime.getSeconds().toString(), // 秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
      };
      for (let k in opt) {
        ret = new RegExp("(" + k + ")").exec(fmt);
        if (ret) {
          fmt = fmt.replace(
            ret[1],
            ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, "0")
          );
        }
      }
      return fmt;
    } catch (e) {
      return;
    }
  }

  //字符串时间转时间
  static strToDateTime(value) {
    return new Date(Date.parse(value.replace(/-/g, "/")));
  }

  //转换成时间搓
  static toTimestamp(date) {
    let timestamp = Date.parse(date);
    return timestamp / 1000; // 1497233827569/1000
  }

  //转换成毫秒级别时间戳
  static toTimestampMs(date) {
    let timestamp = Date.parse(date);
    return timestamp; // 1497233827569
  }

  //获取当前时间戳
  static get getTimestampNow() {
    return new Date().valueOf();
  }

  //获取时间差
  static timeDistance(aDate, bDate) {
    const distance = aDate.getTime() - bDate.getTime(); //时间差的毫秒数
    return distance;
  }

  //获取字符串时间天数
  static strTimeDistanceDay(aStrDate, bStrDate) {
    const end_date = new Date(bStrDate); //将字符串转化为时间
    const sta_date = new Date(aStrDate);
    const num = (end_date - sta_date) / (1000 * 3600 * 24); //求出两个时间的时间差，这个是天数
    if (num > 0) {
      return parseInt(Math.ceil(num));
    } else {
      return 0;
    }
  }

  //获取字符串时间差
  static strTimeDistance(aStrDate, bStrDate) {
    console.log("===>598===>", aStrDate, bStrDate);
    const end_date = sys.strToDateTime(bStrDate); //将字符串转化为时间
    const sta_date = sys.strToDateTime(aStrDate);
    return end_date - sta_date;
  }

  //判断字符串时间是否在两个时间范围内
  static strTime3DateMediation(beginStrDate, aStrDate, endStrDate) {
    const begin_StrDate = sys.strToDateTime(beginStrDate); //将字符串转化为时间
    const a_StrDate = sys.strToDateTime(aStrDate);
    const end_StrDate = sys.strToDateTime(endStrDate);

    if (a_StrDate - begin_StrDate > 0 && a_StrDate - end_StrDate < 0) {
      return true;
    } else {
      return false;
    }
  }

  //获取文件名后缀
  static getFileSuffix(FileUrl) {
    let ret = "png";
    const index = FileUrl.lastIndexOf(".");
    ret = FileUrl.substr(index + 1);
    return ret;
  }

  //经度 longitude 纬度latitude
  static alert(aStr) {
    if (typeof aStr == "object") {
      alert(JSON.stringify(aStr), "", [{text: "确定"}]);
    } else if (typeof aStr == "string") {
      alert(aStr, "", [{text: "确定"}]);
    } else if (typeof aStr == "number") {
      alert(aStr.toString(), "", [{text: "确定"}]);
    } else {
      alert(aStr);
    }
  }

  static rand_number(min, max) {
    return min + Math.random() * (max - min + 1);
  }

  static rand_string(randomFlag = "123", min = 8, max = 16) {
    let str = "",
      range = min,
      arr = [
        "0",
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9",
        "a",
        "b",
        "c",
        "d",
        "e",
        "f",
        "g",
        "h",
        "i",
        "j",
        "k",
        "l",
        "m",
        "n",
        "o",
        "p",
        "q",
        "r",
        "s",
        "t",
        "u",
        "v",
        "w",
        "x",
        "y",
        "z",
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "H",
        "I",
        "J",
        "K",
        "L",
        "M",
        "N",
        "O",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "U",
        "V",
        "W",
        "X",
        "Y",
        "Z",
      ];
    // 随机产生
    if (randomFlag) {
      range = Math.round(Math.random() * (max - min)) + min;
    }
    for (let i = 0; i < range; i++) {
      let pos = Math.round(Math.random() * (arr.length - 1));
      str += arr[pos];
    }
    return str;
  }

  //判断是否为空
  static is_empty(v) {
    //先单独判断数组
    if (Object.prototype.toString.call(v) === '[object Array]') {
      if (v.length === 0) {
        return true;
        return
      }
    }
    switch (typeof v) {
      case "undefined":
        return true;
      case "string":
        if (v.length === 0) return true;
        break;
      case "boolean":
        if (!v) return true;
        break;
      case "number":
        if (0 === v) return true;
        break;
      case "object":
        if (null === v) return true;
        if (Object.keys(v).length == 0) return true;
        break;
      default:
        break;
    }
    return false;
  }

  static encodeURI(url) {
    return encodeURI(url);
  }

  static strToJson(aStr) {
    return JSON.parse(aStr);
  }

  static jsonToStr(aJson) {
    return JSON.stringify(aJson);
  }

  static strToXinStr(str, frontLen, endLen) {
    if (sys.is_empty(str)) {
      return str;
      return;
    }
    if ((str.length + 3) < (frontLen + endLen)) {
      return str;
      return;
    }

    return str.substring(0, frontLen) + " *** " + str.substring(str.length - endLen);
  }

  static hexToString(hexStr) {
    let arr = hexStr.split("");
    let out = "";
    for (let i = 0; i < arr.length / 2; i++) {
      let tmp = "0x" + arr[i * 2] + arr[i * 2 + 1];
      let charValue = String.fromCharCode(tmp);
      out += charValue;
    }
    return out;
  }

  static stringToHex(str) {
    var val = "";
    for (var i = 0; i < str.length; i++) {
      if (val === "") val = str.charCodeAt(i).toString(16);
      else val += str.charCodeAt(i).toString(16);
    }
    return val;
  }

  //字符串截取添加省略号
  static stringCutsub(str, len) {
    if (!str || !len) {
      return "";
    }
    let build = "";
    for (let i = 0; i < str.length && len > 0; i++) {
      build += str.substr(i, 1);
      len -= str.charCodeAt(i) > 127 ? 2 : 1;
    }
    if (build.length < str.length) build += "...";
    return build;
  }

  // 居中剪裁
  static clipImage(img, ops) {
    // 图片原始尺寸
    const imgNaturalWidth = img.naturalWidth;
    const imgNaturalHeight = img.naturalHeight;

    // 剪切尺寸，默认值为原图狂傲
    let clippedWidth = ops.width || imgNaturalWidth;
    let clippedHeight = ops.height || imgNaturalHeight;
    let clippedRatio = clippedWidth / clippedHeight;

    // 居中剪裁的坐标
    let dx = (imgNaturalWidth - clippedWidth) / 2;
    let dy = (imgNaturalHeight - clippedHeight) / 2;

    // 创建画布，并设定尺寸为剪切后的尺寸
    let cvs = document.createElement("canvas");
    const ctxWidth = 300;
    const ctxHeight = ctxWidth / clippedRatio;
    cvs.width = ctxWidth;
    cvs.height = ctxHeight;

    // 绘制图片
    let ctx = cvs.getContext("2d");
    ctx.drawImage(
      img,
      dx,
      dy,
      clippedWidth,
      clippedHeight,
      0,
      0,
      ctxWidth,
      ctxHeight
    );

    // 返回base64图片
    return cvs.toDataURL("image/jpeg", 0.9);
  }

  //设置mate标签,
  static setMate(aName, aContent) {
    let oMeta = document.createElement("meta");
    oMeta.name = aName;
    oMeta.content = aContent;
    document.getElementsByTagName("head")[0].appendChild(oMeta);
  }

  //设置一个Favicon
  static setFaviconIco(iconPath) {
    let link = document.createElement("link");
    link.type = "image/x-icon";
    link.rel = "shortcut icon";
    link.href = iconPath;
    document.getElementsByTagName("head")[0].appendChild(link);
  }

  //插入javascript代码
  static insertScript(aScript) {
    let script = document.createElement("script");
    script.type = "text/javascript";
    script.appendChild(document.createTextNode(aScript));
    document.body.appendChild(script);
  }

  //插入javascript代码url地址
  static insertScriptUrl(url, callback) {
    var script = document.createElement("script");
    script.type = "text/javascript";
    if (script.readyState) {
      script.onreadystatechange = function () {
        if (script.readyState == "loaded" || script.readyState == "complete") {
          script.onreadystatechange = null;
          if (callback) callback();
        }
      };
    } else {
      script.onload = function () {
        if (callback) callback();
      };
    }
    script.src = url;
    document.body.appendChild(script);
  }

  //插入html代码
  static insertHtml(aId, aHtml) {
    let div = document.getElementById(aId);
    if (!sys.is_empty(div)) {
      div.innerHTML = div.innerHTML + aHtml;
    }
  }

  //插入html代码第二种方法,可以出发事件
  /*     static insertHtmlreact(aId,aHtml){
        ReactDOM.render(aHtml, document.getElementById(aId));
    } */

  //替换节点
  static replaceHtml(aId, aHtml) {
    let aDom = document.getElementById(aId);
    if (!sys.is_empty(aDom)) {
      let parent = aDom.parentElement;
      parent.replaceChild(sys.strToHtml(aHtml), aDom);
    }
  }

  //字符串换行为html元素node节点
  static strToHtml(aHtml) {
    let newchild = document.createElement("div");
    newchild.innerHTML = aHtml;
    return newchild.childNodes[0];
  }

  //在body中插入标签
  static insertHtmlBody(aHtml) {
    document.body.appendChild(sys.strToHtml(aHtml));
  }

  //添加注释内容
  static insertComment(aText) {
    document.body.appendChild(document.createComment(aText));
  }

  //显示dom
  static domShow(aId) {
    let aDom = document.getElementById(aId);
    if (!sys.is_empty(aDom)) {
      aDom.style.visibility = "visible";
    }
  }

  //隐藏dom
  static domHide(aId) {
    let aDom = document.getElementById(aId);
    if (!sys.is_empty(aDom)) {
      aDom.style.visibility = "hidden";
    }
  }

  //不是很好的方法检测id是否显示
  static domCheckIsShow(aId) {
    let aDom = document.getElementById(aId);
    if (!sys.is_empty(aDom)) {
      if (aDom.style.visibility === "hidden") {
        return false;
      } else {
        return true;
      }
    } else {
      return false;
    }
  }

  //追加html代码
  static appendChild(aId, aHtml) {
    let div = document.getElementById(aId);
    if (!sys.is_empty(div)) {
      div.appendChild(aHtml);
    }
  }

  //删除元素
  static deleteHtml(aId) {
    let div = document.getElementById(aId);
    if (!sys.is_empty(div)) {
      div.remove();
    }
  }

  //get获取数据
  static axiosGet(aUrl, callback, errorcallback) {
    axios
      .get(aUrl)
      .then((response) => response.json())
      .then((e) => {
        if (callback) {
          callback(e);
        }
      })
      .catch((e) => {
        if (errorcallback) {
          errorcallback(e);
        }
      });
  }

  //url转换成json数据
  static urlToJson(aUrl) {
    let abc = aUrl.split("?")[1];
    let obj = {};
    if (sys.is_empty(abc)) return obj;
    let arr = abc.split("&");
    if (!sys.is_empty(arr)) {
      for (let i of arr) {
        obj[i.split("=")[0]] = i.split("=")[1];
      }
    }
    return obj;
  }

  //设置持久保存数据
  static setItemJson(aName, aValue) {
    return localStorage.setItem(aName, JSON.stringify(aValue));
  }

  //填充空的字符串
  static strFullNull(str) {
    if (str == null) {
      return ""
    } else {
      return str
    }
  }

  //读取持久保存数据
  static getItemJson(aName) {
    const res = localStorage.getItem(aName);
    try {
      return JSON.parse(res);
    } catch (error) {
      return res;
    }
  }

  //设置持久保存数据字符串
  static setItem(aName, aValue) {
    return localStorage.setItem(aName, aValue);
  }

  //读取持久保存数据 字符串
  static getItem(aName) {
    return localStorage.getItem(aName);
  }

  //删除指定数据
  static removeItem(aName) {
    localStorage.removeItem(aName);
  }

  //******************************
  static aryDel(aAry, aIndex) {
    if (aIndex < aAry.length) {
      return aAry.splice(aIndex, 1);
    } else {
      return aAry;
    }
  }

  //查找字符串是否存在
  static pos(apos, aStr) {
    return aStr.indexOf(apos);
  }

  //字符串转换成代码执行 that用来传递的
  static strRunScript(aStr, that) {
    if (that != null) {
      aStr = aStr.replace("this.", "that.");
    }
    eval(aStr);
  }

  static fakeClick = (obj) => {
    var ev = document.createEvent("MouseEvents");
    ev.initMouseEvent(
      "click",
      true,
      false,
      window,
      0,
      0,
      0,
      0,
      0,
      false,
      false,
      false,
      false,
      0,
      null
    );
    obj.dispatchEvent(ev);
  };

  /**
   * 文件下载
   */
  static downloadFile = (fileName, blobData) => {
    let urlObject = window.URL || window.webkitURL || window;
    let export_blob = new Blob([blobData]);
    let save_link = document.createElementNS(
      "http://www.w3.org/1999/xhtml",
      "a"
    );
    save_link.href = urlObject.createObjectURL(export_blob);
    save_link.download = fileName;
    sys.fakeClick(save_link);
  };

  /*axios.get(`/api/store/stuffFrom/exportList/155?isHave=true`, {
        data: {
          "isHave": true,
        },

        Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqd3RfdXNlcmluZm8iOnsiZG9tYWluSWQiOiJmbG93IiwiZGVwYXJ0SWQiOm51bGwsInVzZXJJZCI6NywidXNlcm5hbWUiOiJ3eWoiLCJyZWFsTmFtZSI6IueOi-mAuOePjyIsInVzZXJUeXBlIjoiMCJ9LCJleHAiOjE2MTUyODk2NzAsInVzZXJfbmFtZSI6Ind5aiIsImp0aSI6IjU5YWI3ZjY4LTk0OGItNDI1Mi04NTNhLTIxMGRkNzlhMWVjOSIsImNsaWVudF9pZCI6ImZsb3ciLCJzY29wZSI6WyJyZWFkIl19.JAPsnk8JQ52ETbSbmsJFKTsr46BjiFCYWVaq-WES8h4",
        // 设置responseType对象格式为blob
        responseType: "blob"
      }).then(res => {
        // 创建下载的链接
        const url = window.URL.createObjectURL(new Blob([res.data],
          // 设置该文件的mime类型，这里对应的mime类型对应为.xlsx格式
          {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'}));
        const link = document.createElement('a');
        link.href = url;
        // 从header中获取服务端命名的文件名
        const fileName = '1.xlsx';
        link.setAttribute('download', fileName);
        document.body.appendChild(link);
        link.click();
      });
      message.success("导出材料文件.")

      return;*/

  //保存xlsx文件
  static downloadFilexlsx = (fileName, blobData) => {
    const url = window.URL.createObjectURL(new Blob([blobData], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'}));
    const link = document.createElement('a');
    link.href = url;
    // 从header中获取服务端命名的文件名
    link.setAttribute('download', fileName);
    document.body.appendChild(link);
    link.click();
  };

  //保存pdf文件
  static downloadFilepdf = (fileName, blobData) => {
    const url = window.URL.createObjectURL(new Blob([blobData], {type: 'application/pdf'}));
    const link = document.createElement('a');
    link.href = url;
    // 从header中获取服务端命名的文件名
    link.setAttribute('download', fileName);
    document.body.appendChild(link);
    link.click();
  };

  //打印pdf
  static printPDF(blobData) {
    const url = window.URL.createObjectURL(new Blob([blobData], {type: 'application/pdf'}));
    let iframe = document.createElement("iframe");
    iframe.setAttribute('style', 'visibility: hidden; height: 0; width: 0; position: absolute;');
    iframe.src = url;
    document.documentElement.appendChild(iframe);
    iframe.onload = () => {
      iframe.contentWindow.print();
    }
  }

  //获取图片base格式
  static getBase64(file) {
    return new Promise((resolve, reject) => {
      const reader = new FileReader();
      reader.readAsDataURL(file);
      reader.onload = () => resolve(reader.result);
      reader.onerror = error => reject(error);
    });
  }

  //获取路径带"/"
  static getFilePath(path) {
    const index = path.lastIndexOf("/");
    if (index != -1) {
      return path.substr(0, index + 1);
    } else {
      return undefined
    }
  }

  static getFileName(path) {
    const index = path.lastIndexOf("/");
    if (index != -1) {
      return path.substr(index + 1);
    } else {
      return undefined
    }
  }

  //嵌套的数据转list数据
  static nestToList(recordList) {
    let ret = []
    const getChild = (ls) => {
      ls.map(item => {
        ret.push(item)
        if (item.children != null) {
          getChild(item.children)
        }
      })
    }
    getChild(recordList)
    return ret
  }

  //数组去重
  static uq(array) {
    return Array.from(new Set(array));
  }

  //获取url的地址的参数,根据参数字段名称getQueryVariable("id")
  static getQueryVariable(variable) {
    let query = window.location.search.substring(1);
    let vars = query.split("&");
    for (let i = 0; i < vars.length; i++) {
      let pair = vars[i].split("=");
      if (pair[0] == variable) {
        return pair[1];
      }
    }
    return (false);
  }

  //获取url传参
  static getQueryParams(url=window.location.href){
    const params = {};
    const queryString = url.split('?')[1];
    if (queryString) {
      const pairs = queryString.split('&');
      for (let i = 0; i < pairs.length; i++) {
        const pair = pairs[i].split('=');
        const key = decodeURIComponent(pair[0]);
        const value = decodeURIComponent(pair[1] || '');
        params[key] = value;
      }
    }
    return params;
  }

  //获取指定字符串右侧    console.log(sys.getRight(patientNoQuery,"="))
  static getRight(aStr, aSub) {
    if (aStr) {
      let index = aStr.lastIndexOf(aSub);
      aStr = aStr.substring(index + 1, aStr.length);
      return aStr;
    } else return ""
  }

  //let mySorts=myData.sort(sys.sorts('age'));
  static sorts(element: string | number) {
    return function (a: { [x: string]: any; }, b: { [x: string]: any; }) {
      let value1 = a[element];
      let value2 = b[element];
      return value1 - value2;
    }
  }

  ////chrome-extension://wechat_app/index.html#/test2?aaa=123123
  static jsonToUrlData(obj){
    const objStr = JSON.stringify(obj);
    return "?obj="+encodeURIComponent(objStr);
  }

  static urlToJsonData(){
    const t=sys.getQueryParams(window.location.href)
    //obj: "{\"aa\":123123,\"bb\":334534,\"dd\":\"232344\"}"
    return JSON.parse(decodeURIComponent(t["obj"]))
  }

  static blobToString(blob){
    return  new Promise((resolve, reject) => {
      const reader = new FileReader();
      reader.onload = () => {
        resolve(reader.result);
      };
      reader.onerror = reject;
      reader.readAsText(blob);
    })
  }

}
